#include<iostream>
using namespace std;
int seqsearch(int r[],int n,int k)
{
	int i=n;   
	r[0]=k;
	while(r[i]!=k)i--;
	return i;
}
void  insertsort(int  r[],int n)
{	int i,j;
   for (i=2; i<=n; i++)
   { 
       r[0]=r[i];j=i-1;  
      while (r[0]<r[j])
       {     
           r[j+1]=r[j];	
	        j--;  	     
        }     
           r[j+1]=r[0];
    }
}
int binsearch(int r[],int low,int high,int k)
{
	if(low>high)return 0;
	else{
		int mid;
		mid=(low+high)/2;
		if(k<r[mid])binsearch(r,low,mid-1,k);
		else if(k>r[mid])binsearch(r,mid+1,high,k);
	            else return mid;
	} 
}
struct  BiNode
{
	int data;
	BiNode *lchild,*rchild;
};
class BiSortTree
{
  public:
 BiSortTree(int r[ ], int n)
	 {   
         for (int i=1; i<=n; i++)
       {   BiNode *s;
         s=new BiNode; 
         s->data=r[i];
         s->lchild=s->rchild=NULL;
         InsertBST(root,s);
       }
	} 
void Release(BiNode *root)
	{
			if(root!=NULL)
	   {
		Release(root->lchild);
		Release(root->rchild);
		delete root;
	   }
	}
     ~ BiSortTree( ){Release(root);}
 void InsertBST(BiNode *root , BiNode *s)
     {
     	if (root==NULL)  
          root=s;
        else  if (s->data<root->data)
                InsertBST(root->lchild, s);
            else   InsertBST(root->rchild, s);
	 }
BiNode *SearchBST(BiNode *root, int k)
     {
     	    if (root==NULL)
            return NULL;
        else if (root->data==k) 
              return root;
           else if (k<root->data) SearchBST(root->lchild,k);
               else SearchBST(root->rchild,k);
	 }
BiNode *getroot(){return root;}
  private:
      BiNode *root;   
};
int H(int k){return k%16;}
int HashSearch1(int ht[ ], int m, int k) 
{    int i,j;
     j=H(k);  
     if (ht[j]==k) return j; 
     i=(j+1)%m;
     while (i!=j)  
     {
         if (ht[i]==k) return i;  
         i=(i+1)%m;   
     }
     if (i==j)return 0;  
}

